#!/usr/bin/python
import random
import string

try:  
    from bsddb import db  
except ImportError:  
    from bsddb3 import db  
print db.DB_VERSION_STRING  
  
def irecords(curs):  
    record = curs.first()  
    while record:  
        yield record  
        record = curs.next()  

adb = db.DB()  
adb.open('db_filename_3',dbtype = db.DB_HASH, flags = db.DB_CREATE)  
for id in range(1,10):
    host = random.choice(['steve','koby','owen','tody','rony','steve1'])
    sex = random.choice(['male','female'])
    #host = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
    #host = string.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a','','0','1','2','3','4','5','6','7','8','9','.'], 36)).replace(' ','')
    #adb.put(name,sex)   
    #adb.put(str(id),name)   
    adb.put( host , str(id))   
    #print {'id':id,'name':name,'sex':sex}

adb.put( 'steve' , 'test')   
          
#for i,w in enumerate('some word for example'.split()):  
#    adb.put(w,str(i))  
      
for key, data in irecords(adb.cursor()):  
    print key,data  

adb.close()  
#print '*'*60 
